<template>
	<view class="content">
		<button @click="createUser">新建用户</button>
		<button @click="userLogin">登录</button>
		<button @click="userLogout">退出登录</button>
		<button @click="createProject">新建项目</button>
		<button @click="searchProject">获取项目列表</button>
	</view>
</template>

<script>
import cloudApi from '@/utils/cloudApi.js';

const users = uniCloud.importObject('users');
export default {
	data() {
		return {};
	},
	onLoad() {},
	methods: {
		async createUser() {
			const res = await cloudApi.call({
				type: 'users/register',
				data: {
					name: '张三1',
					phonenumber: '12345',
					password: '1234'
				}
			});
			console.log(res);
		},
		async userLogin() {
			const res = await cloudApi.call({
				type: 'users/login',
				data: {
					phonenumber: '12345',
					password: '1234'
				}
			});
			uni.setStorageSync('TOKEN', res.token);
		},
		userLogout() {
			uni.setStorageSync('TOKEN', '');
		},
		async createProject() {
			const res = await cloudApi.call({
				type: 'projects/add',
				data: {
					name: '张雪峰',
					tel: '111111111',
					price: 21111,
					rooms: [
						{
							name: 'room1',
							totalPrice: 111,
							place: [
								{
									width: 1.2,
									height: 2.2,
									price: 40
								}
							]
						},
						{
							name: 'room12',
							totalPrice: 333,
							place: [
								{
									width: 13.2,
									height: 12.2,
									price: 60
								}
							]
						}
					]
				}
			});
		},
		async searchProject() {
			const res = await cloudApi.call({
				type: 'projects/search',
				data: {
					tel: '111111111'
				}
			});
		}
	}
};
</script>

<style lang="scss">
.user-list {
	.user-item {
		border: 1px solid #ddd;
		margin: 6px;
	}
}
</style>
